﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using nwrole.plugin;

namespace nwrole.lib {
  public abstract class PluginProviderBase {

    [System.ComponentModel.Composition.ImportMany]
    IEnumerable<IPlugin> Plugins { get; set; }
    public int SupervisorPort { get; set; }
    public string ServiceName { get; set; }
    public bool IsInitialized { get; set; }

    public event NwroleSettingsChangedHandler SettingsChangedEvent;

    public void SetServiceName(string serviceName) {
      this.ServiceName = serviceName;
    }

    public IPlugin[] GetPlugins() {
      return Plugins.ToArray();
    }


    public abstract void RefreshPlugins();
    public abstract PropertyList LoadPluginSettings();
    public abstract void SavePluginSettings(PropertyList plist);

    public virtual void Initialize() {
      this.IsInitialized = true;
    }

    protected void OnPluginSettingsChanged(EventArgs e)
    {
        if (SettingsChangedEvent != null)
            SettingsChangedEvent(this, e);
    }
  }
}
